﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AccountManagerTests.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Summary description for AccountManagerTests
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Business.Tests
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Common;
    using Data.Interfaces;
    using Entities;
    using Mapping;

    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Moq;

    /// <summary>
    /// Defines the <seealso cref="Hisaab.Business.Tests.AccountManagerTests"/> type.
    /// </summary>
    [TestClass]
    public class AccountManagerTests
    {
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <param name="context">The context.</param>
        [ClassInitialize]
        public static void Initialize(TestContext context)
        {
            ObjectMapper.AddProfile(new BusinessMapping());
        }

        /// <summary>
        /// Constructors the should thorw if account repository is null.
        /// </summary>
        [TestMethod, ExpectedException(typeof(ArgumentNullException))]
        public void ConstructorShouldThorwIfAccountRepositoryIsNull()
        {
            var mockTransactionRepository = new Mock<ITransactionRepository>();
            new AccountManager(null, mockTransactionRepository.Object);
        }

        /// <summary>
        /// Constructors the should thorw if transaction repository is null.
        /// </summary>
        [TestMethod, ExpectedException(typeof(ArgumentNullException))]
        public void ConstructorShouldThorwIfTransactionRepositoryIsNull()
        {
            var mockAccountRepository = new Mock<IAccountRepository>();
            new AccountManager(mockAccountRepository.Object, null);
        }

        /// <summary>
        /// Lists the should call the query method on repository.
        /// </summary>
        [TestMethod]
        public void ListShouldCallTheQueryMethodOnRepository()
        {
            var mockAccountRepository = new Mock<IAccountRepository>();
            var mockTransactionRepository = new Mock<ITransactionRepository>();
            IQueryable<Data.Entities.Account> mockResult = new List<Data.Entities.Account>().AsQueryable();

            mockAccountRepository.Setup(x => x.Query(It.IsAny<Data.Entities.Account>(), 12, 23))
                .Returns(mockResult)
                .Verifiable();

            var manager = new AccountManager(mockAccountRepository.Object, mockTransactionRepository.Object);
            manager.List(new Account(), 12, 23);

            mockAccountRepository.VerifyAll();
        }
    }
}